11. Installing Postgres

Installing Postgres Heading

Installing Postgres

ND004 C01 L02 15 Installing Postgres

Install Postgres

Before we can use Postgres, we'll need to install it. You may already have Postgres, for example if you're a MacOS user, it already comes installed on your machine. But just in case, here are some steps for downloading and installing it.

Go to the Postgres Download page and download Postgres for your machine.

You should know that you successfully installed Postgres if you can run the following in your terminal, and see a path outputted:

$ which postgres
/usr/local/bin/postgres

Next: Start a Postgres server on your local machine

For MacOS Users :

From the Postgres.app , it's as simply as hitting the "Initialize" button. Follow the instructions on the Postgres.app homepage to configure and initialize a postgres server.

From the command line:

On MacOS, to stop an already initialized postgres server

$ pg_ctl -D /usr/local/var/postgres stop

to start a postgres server

$ pg_ctl -D /usr/local/var/postgres start

See How to start, stop, and restart a postgresql server to follow steps for your particular operating system.

Initial installation settings

The initial installation will:

  • create an initial database named postgres
  • create an initial user named postgres . Your postgres user will have no password set by default.
  • create initial databases called template1 and template0 . Any other database created after template1 is a clone of template1 , including its tables and rows. If you add rows (objects) to template1 , they will be copied onto future created databases. template0 , on the other hand, should stay "pure" and never be changed.
  • The default host machine that runs your postgres server, on your machine, is localhost (aka, 127.0.0.1 )
  • The default port traditionally used to host your server is port 5432 . There are very few reasons to use a different port than 5432 .

Default connection settings are:

Field Default Value
Host localhost
Port 5432
Username postgres
Password (left blank)

Additional References:

Let's deep dive into what Postgres is

  • Postgres is an open source, general purpose and object-relational database management system , considered by many to be the most advanced open source database system available. It's a relational database system extended with object-oriented features, that works across operating systems.

    • Object-relational support includes support for arrays (multiple valuesin a single column), and inheritance (child-parent relationships between tables).
  • Built since 1977, it is lauded for being highly stable , requiring minimal effort to maintain compared to other systems.

  • Widely used , everywhere: by Apple, Cisco, Etsy, Microsoft, Yahoo, Reddit, Instagram, Uber,… and many others.

  • Comprehensive suport for the SQL standard.

  • Transaction -based: operations on the database are done through atomic transactions.

  • Has multi-version concurrency control , avoiding unnecessary locking when multiple writes are happening to the database at once (avoiding waiting times for access to the database)

    • Postgres lets you have several databases available for reading from and writing to, at once.
  • Offers great performance and many indexing capabilities for optimizing query performance

  • PostgreSQL is also often just called Postgres, and we'll be using both terms interchangeably throughout this course.